package com.yanjue.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanjue.common.constant.CategoryConstant;
import com.yanjue.common.entity.Book;
import com.yanjue.common.enums.BookSerialStatusEnum;
import com.yanjue.common.util.Result;
import com.yanjue.common.util.ResultUtil;
import com.yanjue.mapper.BookMapper;
import com.yanjue.service.BookService;
import com.yanjue.vo.BookVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author yanju
* @description 针对表【book(图书表)】的数据库操作Service实现
* @createDate 2025-01-16 12:33:44
*/
@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book>
    implements BookService {

    @Autowired
    private BookMapper bookMapper;
    /**
     * 获取图书详情
     *
     * @param bookId
     * @return
     */
    @Override
    public Result getBookDetails(String bookId) {
        Book book = bookMapper.selectById(bookId);
        if (book == null){
            return ResultUtil.notFound().buildMessage("找不到" + bookId+"这本书");
        }
        BookVO vo = new BookVO();
        BeanUtils.copyProperties(book,vo);
        //将分类和连载状态赋值到vo里
        vo.setCategoryName(CategoryConstant.categorys.get(book.getDicCategory()));
        vo.setSerialStatusName(BookSerialStatusEnum.fromValue(book.getDicSerialStatus()).getName());
        return ResultUtil.success(vo);
    }
}




